/*var vm = new Vue({
 el: '#res',
 name: 'Login',
 data: function (router) {
 return {
 section: 'Login',
 loading: '',
 username: '',
 password: '',
 response: ''
 }
 },
 methods: {
 onSubmitClick:function(e){
 var self=this;
 Vue.http.post("http://euvee.vicp.co/token",self.username,self.password, function (data, status, request) {
 var i = data.length;
 success_callback(data, status, request);
 }).catch(function (data, status, request) {
 if (error_callback != null) {
 error_callback(data, status, request);
 }
 });
 }*/
/* checkCreds: function () {
 //  Change submit button
 var self = this
 var store = this.$store

 this.toggleLoading()
 this.resetResponse()
 store.dispatch('TOGGLE_LOADING')

 //  Login
 this.$parent.callAPI('POST', '/login', { username: this.username, password: this.password }).then(function (response) {
 store.dispatch('TOGGLE_LOADING')

 if (response.data) {
 var data = response.data

 if (data.error) {
 if (data.error.name) { //  Object from LDAP at this point
 switch (data.error.name) {
 case 'InvalidCredentialsError' : self.response = 'Username/Password incorrect. Please try again.'; break
 default: self.response = data.error.name
 }
 } else {
 self.response = data.error
 }
 } else {
 //  success. Let's load up the dashboard
 if (data.user) {
 store.dispatch('SET_USER', data.user)
 var token = 'Bearer ' + data.token
 store.dispatch('SET_TOKEN', token)

 // Save to local storage as well
 /!*  if (window.localStorage) {
 window.localStorage.setItem('user', JSON.stringify(data.user))
 window.localStorage.setItem('token', token)
 }*!/
 if(window.localStorage){
 alert('This browser supports localStorage');
 }else{
 alert('This browser does NOT support localStorage');
 }

 this.$router.go(data.redirect)
 }
 }
 } else {
 self.response = 'Did not receive a response. Please try again in a few minutes'
 }

 self.toggleLoading()
 }, function (response) {
 // error
 store.dispatch('TOGGLE_LOADING')
 console.log('Error', response)
 self.response = 'Server appears to be offline'
 self.toggleLoading()
 })
 },
 toggleLoading: function () {
 this.loading = (this.loading === '') ? 'loading' : ''
 },
 resetResponse: function () {
 this.response = ''
 }*/
/*
 }
 })
 */

var AppService = {
  urlroot: "http://euvee.vicp.co/token",
  init: function () {
    Vue.http.options.root = this.urlroot;
    Vue.http.options.emulateJSON = true;
  },
  //初始化引入数据
  login: function (user, success_callback, error_callback) {
    var url = this.urlroot;
    Vue.http.post(url,user, function (data, status, request) {
      success_callback(data, status, request);
    }).catch(function (data, status, request) {
      if (error_callback != null) {
        error_callback(data, status, request);
      }
    });
  }
};
var svc = Object.create(AppService);

var vm = new Vue({
  el: '#res',
  data: {
    username: '',
    password: ''
  },
  methods: {
    onSubmitClick: function (user, e) {
      var xmlHttp=new XMLHttpRequest();
      var self = this;
      var formData = new FormData(document.forms.namedItem("loginForm"));
      $.ajax({
        url: "http://euvee.vicp.co/token",
        data: formData,// 你的formid,
        type: "POST",
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function (data) {
          alert(data.token);
/*          function createAuthorizationTokenHeader() {
            var token = data.token;
           // xmlHttp.setRequestHeader("Authorization", data.token);
            if (token) {
              return {"Authorization": token};
            } else {
              return {};
            }
          }*/
         $.ajax({
            url: "http://euvee.vicp.co/rest/fdb",
            type: "GET",
         /*   headers: createAuthorizationTokenHeader()*/
           headers: {
             'Token': data.token
           }
          });

         // Vue.http.headers.common['Authorization'] = '121';
      /*    xmlHttp.setRequestHeader("Authorization", '121');
          Vue.http.get("http://euvee.vicp.co/rest/fdb/", function (data, status, request) {

          }).catch(function (data, status, request) {
          })*/
        }
      });
    }
  }
});
